package meituan;

import java.util.Scanner;

/**
 * 美团点评 求正数整型数组中，连续子数组中累加和为k的最大连续子数组的大小
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int k = sc.nextInt();

        System.out.println(getMulMaxLength(arr,k));
    }

    /**
     * 求正数整型数组中，连续子数组中累加和为k的倍数最大连续子数组的大小
     * @param arr
     * @param k
     * @return
     */
    private static int getMulMaxLength(int[] arr, int k) {
        if (arr == null || arr.length == 0 || k <= 0) {
            return 0;
        }

        int sum = 0;
        for (int a : arr) {
            sum += a;
        }

        int mulK = 0;
        mulK = sum / k * k; // k的最大倍
        int max = 0;
        int maxTmp = 0;
        while ( mulK >= k) {
            maxTmp = getMaxLength(arr, mulK);
            if (maxTmp > max) {
                max = maxTmp;
            }
            mulK -= k;
        }
        return max;
    }

    /**
     * 求正数整型数组中，连续子数组中累加和为k的最大连续子数组的大小
     * @param arr
     * @param k
     * @return
     */
    private static int getMaxLength(int[] arr, int k) {
        if (arr == null || arr.length == 0 || k <= 0) {
            return 0;
        }
        int n = arr.length;
        int left = 0;
        int right = 0;
        int sum = arr[0];
        int len = 0;
        while(right < n) {
            if (sum == k) {
                len = Math.max(len, right - left + 1);
                sum -= arr[left++];
            } else if (sum < k) {
                right++;
                if (right == n) break;
                sum += arr[right];
            } else {
                sum -= arr[left++];
            }
        }
        return len;
    }
}
